{% extends "templates/base.phtml" %}
{%block content%}
{% if wxc is defined %}
<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default tabs">
                <ul class="nav nav-tabs" role="tablist">
                    <li class="active"><a href="admin/appvote">投票列表</a></li>
                </ul>
                <div class="panel-body tab-content">
                    <div class="tab-pane active">
                        <div class="col-md-12">

                                <h3>投票列表</h3>
                                <div class="form-group">
                                    <label class="col-md-1 col-xs-5 control-label">列表地址：</label>
                                    <div class="col-md-6 col-xs-5 ">
                                        <input type="text" class="form-control " value="{{voteListUrl}}" >
                                    </div>
                                    <a class="btn btn-success" href="{{voteListUrl}}">预览</a>
                                    <a class="btn btn-success pull-right" href="/admin/appvote/create">+新建投票</a>
                                </div>

                            <!--表-->

                                <table class="table table-bordered">
                                    <thead>
                                    <tr>
                                        <th>编号</th>
                                        <th>名称</th>
                                        <th>类型</th>
                                        <th>状态</th>
                                        <th>总投票数</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            {% for votesArr in page.items %}
                                            <td>
                                                <p>{{votesArr['id']}}</p>
                                            </td>

                                            <td>
                                                <p>{{votesArr['name']}}</p>
                                            </td>

                                            <td>
                                                <p>{%if votesArr['type']==1%}单选{%else%}多选{%endif%}</p>
                                            </td>

                                            <td>
                                                <p>{%if votesArr['state']==1%}文字投票{%else%}图片投票{%endif%}</p>
                                            </td>

                                            <td>
                                                <p>{{votesArr['count']}}</p>
                                            </td>

                                            <td>
                                                <a class="btn btn-primary" type="button" href="/frontend/vote/detail?token={{votesArr['token']}}&id={{votesArr['id']}}" >预览</a>
                                                <a class="btn btn-primary" type="button" href="/admin/appvote/update?token={{votesArr['token']}}&id={{votesArr['id']}}" >修改</a>
                                                <button class="btn btn-danger" onclick="deleteConfirm({{votesArr['id']}})">
                                                    删除
                                                </button>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                    </table>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{%endif%}
<!-- END PAGE CONTENT WRAPPER -->
{%endblock%}
{%block end%}
<style type="text/css">
    .control-label{
        margin-top: 8px;
    }
    table{
        margin-top: 15px;
    }
    table th, table td {
        text-align: center;
    }
</style>
<script type="text/javascript">
    function deleteConfirm(delete_id){
        noty({
            text: '确定要删除此投票吗?',
            layout: 'topRight',
            buttons: [
                {addClass: 'btn btn-success btn-clean', text: '确定', onClick: function($noty) {
                    $noty.close();
                    $.post('/admin/appvote/delete/'+delete_id,{},function(result){


                        noty({text: '删除成功', layout: 'topRight', type: 'success'}
                        );location.reload();
                    });
                }
                },
                {addClass: 'btn btn-danger btn-clean', text: '取消', onClick: function($noty) {
                    $noty.close();
                }
                }
            ]
        })
    }
</script>
{%endblock%}